﻿<%@ Page Title="Model" Language="C#" MasterPageFile="~/App_MasterPages/Aquarius.Master"
    AutoEventWireup="true" CodeBehind="ModelManagement.aspx.cs" Inherits="PanasonicWarranty.UI.ModelManagement"  %>

<%@ Register Src="../UserControl/ucPaging.ascx" TagName="ucPaging" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="CssContent" runat="server">
    <link href="../css/uploadify.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ScriptContent" runat="server">
    <script src="../js/jquery.uploadify.js" type="text/javascript"></script>
    <script src="../js/pana_authorization.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            RegisterDialog();
            ComboBox("ddlCateCode");
            $("[id$='fuImport']").fileUpload({
                'uploader': '../js/uploader.swf',
                'cancelImg': '../img/cancel.png',
                'buttonText': 'Browse Files',
                'script': '../Handler/UpLoad1.ashx',
                'fileDesc': 'Excel file',
                'fileExt': '*.xls;*.xlsx;',
                'multi': false,
                'auto': false,
                'onComplete': function (file, data, response, c) {
                    $("#spUploadResult").html(c);
                }
            });
        });
   
        function SetApprovedRequired(checkbox) {
            var checked = checkbox.checked;
            var modelcode = $(checkbox).parent().find(":hidden").val();
            $.ajax({
                type: "POST",
                url: 'ModelManagement.aspx/SetApprovedRequired',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                beforeSend: function () {
                    $("#progress").show();
                },
                complete: function () {
                    $("#progress").hide();
                },
                data: "{'required':" + JSON.stringify(checked) + ", 'modelCode':" + JSON.stringify(modelcode) + "}",
                error: function () {
                    $(checkbox).prop("checked", !checked);
                },
                async: false
            });
        }
    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <div class="row-fluid">
        <div class="span12">
            <div class="head">
                <div class="isw-grid">
                </div>
                <h1>Điều kiện tìm kiếm</h1>
                <div class="clear"></div>
            </div>
            <div class="block-fluid" style="padding: 10px 0px 5px 10px">
                <table width="100%" cellspacing="0" cellpadding="0" class="">
                    <tbody>
                        <tr>
                            <td>Model sản phẩm</td>
                            <td><asp:TextBox ID="txtSearchModelCode" runat="server" /></td>
                        </tr>
                        <tr>
                            <td>Nhóm sản phẩm</td>
                            <td><asp:TextBox ID="txtSearchCateCode" runat="server" /></td>
                        </tr>
                        <tr>
                            <td>Thời hạn bảo hành</td>
                            <td>
                                <asp:TextBox ID="txtSearchPeriod" runat="server" />
                                <asp:DropDownList ID="ddlSearchPeriodType" runat="server" style="width:80px;">
                                    <asp:ListItem Value="month">Tháng</asp:ListItem>
                                </asp:DropDownList>
                            </td>
                        </tr>
                        <tr>
                            <td>Yêu cầu Happy call</td>
                            <td>
                                <asp:DropDownList ID="ddlSearchHappyCall" runat="server">
                                    <asp:ListItem Value="">-----</asp:ListItem>
                                    <asp:ListItem Value="true">Có</asp:ListItem>
                                    <asp:ListItem Value="false">Không</asp:ListItem>
                                </asp:DropDownList>
                            </td>
                        </tr>
                    </tbody>
                </table>
                <div style="text-align: center">
                    <asp:Button ID="btnSearch" runat="server" Text="Tìm kiếm" OnClick="btnSearch_Click"
                        CssClass="btn" />
                </div>
            </div>
        </div>
    </div>
    <div class="row-fluid">
        <div class="span12">
            <div class="head">
                <div class="isw-grid"></div>
                <h1>Danh mục Model</h1>
                <ul class="buttons">
                    <li><asp:LinkButton CssClass="isw-download" ID="btnDownload" runat="server" 
                            ToolTip="Download mẫu file upload" onclick="btnDownload_Click" /></li>
                    <li><asp:LinkButton CssClass="isw-cloud" ID="btnExport" runat="server"
                            ToolTip="Export dữ liệu" OnClick="btnExport_Click" /></li>
                    <li><asp:LinkButton CssClass="isw-attachment" ID="btnUpload" runat="server" 
                            ToolTip="Import danh mục model" OnClientClick="$('#spUploadResult').html(''); return OpenDialog('dialog2',400);" /></li>
                    <li><asp:LinkButton CssClass="isw-plus" ID="lbtnAddNew" runat="server" onclick="lbtnAddNew_Click" /></li>
                </ul>
                <div class="clear">
                </div>
            </div>
            <div class="block-fluid table-sorting">
                <div class="dataTables_wrapper" id="tSortable_wrapper">
                    <div class="dataTables_length">
                        <label>
                            Hiển thị
                            <asp:DropDownList ID="tSortable_length" size="1" aria-controls="tSortable" runat="server"
                                OnSelectedIndexChanged="tSortable_length_SelectedIndexChanged" AutoPostBack="true">
                                <asp:ListItem Value="5">5</asp:ListItem>
                                <asp:ListItem Value="10">10</asp:ListItem>
                                <asp:ListItem Value="25">25</asp:ListItem>
                                <asp:ListItem Value="50" Selected="True">50</asp:ListItem>
                                <asp:ListItem Value="100">100</asp:ListItem>
                            </asp:DropDownList>
                            dòng</label>
                    </div>
                    <div>
                        <uc1:ucPaging ID="pagingtop" runat="server" />
                    </div>
                    <asp:GridView ID="grvData" CssClass="table2 dataTable" runat="server" 
                        AutoGenerateColumns="false" Width="100%"
                        ShowHeaderWhenEmpty="true" onrowcommand="grvData_RowCommand">
                        <Columns>
                            <asp:TemplateField HeaderText="STT" ItemStyle-CssClass="STT">
                                <ItemTemplate>
                                    <%#(Container.DataItemIndex + 1) + (pagingtop.CurrentPage - 1) * pagingtop.PageSize%>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField HeaderText="Model" DataField="ModelCode" ItemStyle-CssClass="width1"/>
                            <asp:BoundField HeaderText="Nhóm sản phẩm" DataField="CateCode" ItemStyle-CssClass="width1"/>
                            <asp:TemplateField HeaderText="Thời hạn BH (tháng)" ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <%#Eval("WarrantyPeriod")%>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField HeaderText="Chi tiêt" DataField="Description" ItemStyle-Width="400px" />
                            <asp:TemplateField HeaderText="Yêu cầu Happy call" ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <input type="hidden" value='<%#Eval("ModelCode")%>' />
                                    <asp:CheckBox runat="server" Checked='<%#Eval("ApprovedRequired")%>' onclick='SetApprovedRequired(this);'  />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField HeaderText="Thời hạn xác nhận BH (ngày)" DataField="ApprovedDuration" ItemStyle-HorizontalAlign="Center"/>
                            <asp:TemplateField HeaderText="Chức năng" ItemStyle-CssClass="Function">
                                <ItemTemplate>
                                    <asp:LinkButton ID="lbtnEdit" Text="Sửa" runat="server"
                                        CommandName="Editing" CommandArgument='<%#Eval("ModelCode")%>' />
                                    &nbsp; &nbsp;
                                    <asp:LinkButton ID="lbtnDelete" Text="Xóa" runat="server"
                                        CommandName="Deleting" CommandArgument='<%#Eval("ModelCode")%>' OnClientClick="return confirm('Bạn có chắc chắn muốn xóa không?');" />
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                    <div class="dataTables_info" id="tSortable_info">
                        <asp:Literal ID="ltrInfo" runat="server" />
                    </div>
                    <div class="dataTables_paginate paging_full_numbers" id="tSortable_paginate">
                        <uc1:ucPaging ID="pagingbottom" runat="server" />
                    </div>
                </div>
                <div class="clear">
                </div>
            </div>
        </div>
    </div>
    <div class="ui-widget-overlay ui-front" id="progress" style="display:none">
        <img src='<%=ResolveUrl("~/images/loading.gif")%>' alt="Loading..." style="position: fixed; top: 50%; left: 50%" />
    </div>
    <div class="dialog" id="dialog1" title="Thông tin Model" style="display: none;">
        <asp:Panel ID="pnl_dialog1" runat="server" CssClass="block">
            <asp:HiddenField ID="hdfID" Value="" runat="server" />
            <table width="100%" cellpadding="2" cellspacing="2" >
                <tr>
                    <td>Model</td>
                    <td><asp:TextBox ID="txtModelCode" runat="server" /></td>
                </tr>
                <tr>
                    <td>Nhóm sản phẩm</td>
                    <td><asp:DropDownList ID="ddlCateCode" runat="server"/></td>
                </tr>
                <tr>
                    <td>Thời hạn bảo hành</td>
                    <td>
                        <asp:TextBox ID="txtPeriod" runat="server" onkeypress="return ValidateKeypress(/\d/, event)"/>
                    </td>
                </tr>
                <tr>
                    <td>Đơn vị thời gian</td>
                    <td>
                        <asp:DropDownList ID="ddlPeriodType" runat="server" style="width:80px;">
                            <asp:ListItem Value="month">Tháng</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td>Chi tiết</td>
                    <td><asp:TextBox ID="txtDescription" runat="server" TextMode="MultiLine" /></td>
                </tr>
                <tr>
                    <td>Yêu cầu happy call</td>
                    <td><asp:CheckBox ID="chkHappyCall" runat="server" /></td>
                </tr>
                <tr>
                    <td>Thời hạn xác nhận BH</td>
                    <td><asp:TextBox ID="txtApprovedDuration" runat="server" onkeypress="return ValidateKeypress(/\d/, event)"/> (Ngày)</td>
                </tr>
            </table>
            <div style="text-align:center; width:100%; color:Red"><asp:Label ID="lbError" runat="server" /></div>
            <div class="dr"><span></span></div>
            <div style="text-align: right">
                <asp:Button ID="btnSave" CssClass="btn" runat="server" Text="Lưu" 
                    onclick="btnSave_Click" />
                <input type="button" class="btn" value="Đóng" onclick="$('#dialog1').dialog('close'); return false;" />
            </div>
        </asp:Panel>
    </div>
    <div class="dialog" id="dialog2" title="Lựa chọn file Import" style="display: none;">
        <asp:Panel ID="pnl_dialog2" runat="server" CssClass="block">
            <div>
                <asp:FileUpload ID="fuImport" runat="server" />
            </div>
            <div style="text-align:center; color:Red">
                <span id="spUploadResult"></span>
            </div>
            <div class="dr"><span></span></div>
            <div style="text-align: right">
                <input type="button" class="btn" value="Import" onclick='$("[id$=fuImport]").fileUploadStart(); return false;' />
                <asp:Button ID="btnCancel" CssClass="btn" Text="Đóng" OnClientClick="$('[id$=fuImport]').fileUploadClearQueue(); $('#dialog2').dialog('close');" runat="server" 
                    OnClick="btnCancel_Click"/>
            </div>
        </asp:Panel>
    </div>
</asp:Content>
